<?php
/**
 * Created by PhpStorm.
 * User: W
 * Date: 2018/12/20
 * Time: 13:27
 */

namespace app\sports_admin\model;


use think\Model;
use think\db;
use think\Request;

//图书类别表
class DataCategory extends Model
{
    protected $table = "data_category";
    protected $pk    = "id";

//    public static function type($request)
//    {
//        $data   = Request::instance()->only('id');
//        return self::where('pid',$data['id'])->value('id');
//    }
    public static function getTypes($page,$rows,$sort,$sortOrder,$searchName)
    {
        $adminList = self::where(function($query)use($searchName){
                if($searchName){$query->where('catname','like',"%{$searchName}%");}
            })
            ->page($page)
            ->limit($rows)
            ->order("{$sort}","{$sortOrder}")->select();

        $adminCount = self::where(function($query)use($searchName){
                if($searchName){$query->where('catname','like',"%{$searchName}%");}
            })
            ->count();
        return ['rows'=>$adminList,'total'=>$adminCount];
    }
}